<template>
  <div class="home">
    <div class="rg-overlay" id="rg-overlay">
      <div
        class="left-top"
        :style="{
          width: ruler + 'px',
          height: ruler + 'px',
        }"
      ></div>
      <div
        class="ruler h unselectable"
        :style="{ width: '', height: ruler + 'px', paddingLeft: ruler + 'px' }"
      >
        <span
          v-for="item in rulerWidth"
          :key="item"
          :class="item % unit === 0 ? 'major' : ''"
          style="position: relative"
        >
          <span
            class="label"
            :style="{ left: `calc( ${ruler} /${unit} * -1)` }"
            v-if="item % unit === 0"
          >{{ item }}</span>
        </span>
      </div>
      <div
        class="ruler v unselectable"
        :style="{ width: ruler + 'px', height: '', paddingTop: ruler + 'px' }"
      >
        <span
          v-for="item in rulerHeight"
          :key="item"
          :class="item % unit === 0 ? 'major' : ''"
          style="position: relative"
        >
          <span class="label" :style="{ left: ' -16px' }" v-if="item % unit === 0">{{ item }}</span>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import { defineComponent, reactive, onMounted } from "vue"
export default defineComponent({
  name: "Home",
  components: {},
  setup () {
    const state = reactive({
      rulerWidth: "",
      rulerHeight: "",
      ruler: 40,
      unit: 20,
    })
    onMounted(() => {
      let rulerElement = document
        .getElementById("rg-overlay")
        .getBoundingClientRect()
      state.rulerWidth = rulerElement.width - 40
      state.rulerHeight = rulerElement.height - 40
      console.log("ctx: ", state)
      console.log("mounted!")
    })
    return state
  },
});
</script>
<style scoped lang="scss">
.rg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  .left-top {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    background: #fff;
  }
  .ruler {
    background-color: #ccc;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9990;
    box-sizing: border-box;
    &.unselectable {
      user-select: none;
    }
    &.h {
      left: -1px;
      padding-top: 14px;
      border-bottom: solid 1px #000;
      text-align: left;
      bottom: 0;
      display: flex;
      justify-content: flex-start;
      align-items: flex-end;
      span {
        border-left: solid 1px #999;
        height: 9px;
        width: 1px;
        vertical-align: center;
        display: inline-block;
        *display: inline;
        zoom: 1;
        &.major {
          border-left: solid 1px #000;
          height: 13px;
        }
        &.label {
          border: 0;
          font-size: 9px;
          position: absolute;
          text-align: center;
          top: -14px;
          left: -7px;
          width: 9px;
          color: #000;
        }
      }
    }
    &.v {
      top: -1px;
      padding-left: 16px;
      width: 25px;
      border-right: solid 1px #000;
      span {
        display: block;
        margin-left: auto;
        margin-right: 0;
        border-top: solid 1px #999;
        width: 9px;
        height: 1px;
        &.major {
          border-top: solid 1px #000;
          width: 13px;
        }
        &.label {
          border: 0;
          font-size: 9px;
          position: absolute;
          text-align: center;
          width: 9px;
          color: #000;
          transform: rotate(-90deg);
        }
      }
    }
    span {
      font-size: 0;
    }
  }
}
</style>
